home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 165 < prev    next >
Encoding:
Text File  |  1996-08-06  |  3.1 KB  |  133 lines

  1. Path: engnews2.Eng.Sun.COM!taumet!clamage
  2. From: krotoff@such.srcc.msu.su (Alexander Krotoff)
  3. Newsgroups: comp.std.c++
  4. Subject: Appendix C (Compatibility)
  5. Date: 29 Jan 1996 19:15:24 GMT
  6. Organization: Research Computer Center, Moscow State University
  7. Sender: krotoff@boy.nmd.msu.ru
  8. Approved: clamage@eng.sun.com (comp.std.c++)
  9. Message-ID: <4eiih2$63u@boy.nmd.msu.ru>
  10. NNTP-Posting-Host: taumet.eng.sun.com
  11. Content-Type: text
  12. Content-Length: 2472
  13. X-Lines: 114
  14. Originator: clamage@taumet
  15.  
  16. Hello c++ gurus,
  17.  
  18. I have some remarks on the Appendix C (Compatibility).
  19.  
  20. ------------------------------------------------------------------------
  21.     C.1.1  C++ features available in 1985
  22.  
  23.     13A pointer to function can be assigned to a void*; _conv.ptr_.
  24.  
  25. Is it correct ?
  26.  
  27. 4.10  Pointer conversions says:
  28. 2    An rvalue of type "pointer to cv T," where T is an object
  29.     type, can be converted  to  an  rvalue of type "pointer to
  30.     cv void."
  31.  
  32. The function type is not object type.
  33. ------------------------------------------------------------------------
  34.     C.1.2  C++ features added since 1985
  35.  
  36. Did you forgot namespaces in this list ?
  37.  
  38. ========================================================================
  39. Additional differences ISO C/C++:
  40. ------------------------------------------------------------------------
  41. In C conversion to pointer types and null pointer constant  may be used
  42. in the constant expression.
  43. In C++ they cannot be used in the context of integral constant expression.
  44.  
  45. ANSI C    3.4
  46. WP C++    expr.const
  47.  
  48. Example:
  49.  
  50. #include <stddef.h>
  51.  
  52. struct A {
  53.     int a;
  54.     int b;
  55. };
  56.  
  57. void f()
  58. {
  59.     int i;
  60.  
  61.     switch (i) {
  62.     case 1:
  63.     case offsetof (struct A, b):
  64.         i--;
  65.     }
  66. }
  67.  
  68. Here I assume semi-standard definition of offsetof macro.
  69.  
  70. ------------------------------------------------------------------------
  71. In C struct member can have the same name, as struct itself.
  72. In C++ it do not.
  73.  
  74. Example:
  75.  
  76. struct a {        // vadid C
  77.     int a;        // invalid C++
  78. };
  79. ------------------------------------------------------------------------
  80. According to Extensions to ANSI C A.6.5.4 C compiler may use additional
  81. scope rules for external objects.
  82. There is no such rule in C++.
  83.  
  84. Of course, this rule is not in the ANSI C itself.
  85.  
  86. Example1:
  87.  
  88. void f(void)
  89. {
  90.     extern int a[];
  91. }
  92.  
  93. void g()
  94. {
  95.     int *pi = a+1;    // Valid C, invalid c++.
  96. }
  97.  
  98. Example2:
  99.  
  100. void f(void)
  101. {
  102.     extern void g(void);
  103. }
  104.  
  105. void h(void)
  106. {
  107.     void (*p)(void) = g;
  108. }
  109.  
  110. ------------------------------------------------------------------------
  111. In C and C++ syntax for empty enum is differnent.
  112. In C enumerator list enclosed in `{}' is not allowed to be empty.
  113. In C++ empty enumerator list is allowed, but '{}'
  114. must be present.
  115.  
  116. C++ WP    dcl.enum
  117. ANSI C    3.5.2.2
  118.  
  119. Example:
  120.  
  121. enum a;            // valid C, invalid C++.
  122. enum {};        // valid C++, invalid C.
  123. ------------------------------------------------------------------------
  124.  
  125. --
  126. Alexander N. Krotoff        krotoff@such.srcc.msu.su
  127. Research Computer Center    tel: +7(095)939-2638
  128. Moscow State University        fax: +7(095)939-4430
  129. [ comp.std.c++ is moderated.  Submission address: std-c++@ncar.ucar.edu.
  130.   Contact address: std-c++-request@ncar.ucar.edu.  The moderation policy
  131.   is summarized in http://dogbert.lbl.gov/~matt/std-c++/policy.html. ]
  132.  
  133.